<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
/**
 * Admin
 */
Route::group([
		'namespace' => 'Admin',
		'domain' => 'admin.'.config('app')['url'],
		#'middleware' => ['admin.auth']
], function (){
	
	// 实现隐式路由
	Route::any('/{class?}/{action?}/{args?}', function($class='Home', $action='__invoke', $args=[NULL]) {
		$class = ucfirst($class);
		$path = "\\App\\Http\\Controllers\\Admin\\";
		$path .= $class . "Controller";
		
		if(is_string($args)){ $args = [$args]; }
		$ctrl = App::make($path);
		return App::call([$ctrl, $action], $args);
	});
		
});

/**
 * Web
 */
Route::group([
    'namespace' => 'Web'
], function (){
	Route::get('cat/{args?}', function ($args=[null]) {
		$path = "\\App\\Http\\Controllers\\Web\\HomeController";
		$ctrl = App::make($path);
		if(is_string($args)){ $args = [$args]; }
        return App::call([$ctrl, 'cat'], $args);
	});

	Route::get('search/{args?}', function ($args=[null]) {
		$path = "\\App\\Http\\Controllers\\Web\\HomeController";
		$ctrl = App::make($path);
		if(is_string($args)){ $args = [$args]; }
        return App::call([$ctrl, 'search'], $args);
	});
	Route::get('article/{args?}', function ($args=[null]) {
		$path = "\\App\\Http\\Controllers\\Web\\HomeController";
		$ctrl = App::make($path);
		if(is_string($args)){ $args = [$args]; }
        return App::call([$ctrl, 'article'], $args);
	});
	#老板兼容
	Route::get('index/view', function ($args=[null]) {
		$id = $_GET['id']??0;
		$args = [$id];
		$path = "\\App\\Http\\Controllers\\Web\\HomeController";
		$ctrl = App::make($path);
        return App::call([$ctrl, 'article'], $args);
		
	});
	Route::get('index/index', function ($args=[null]) {
		$cat_id = $_GET['cat_id']??0;
		$page = $_GET['page']??0;
		$args = [$cat_id,$page];
		$path = "\\App\\Http\\Controllers\\Web\\HomeController";
		$ctrl = App::make($path);
        return App::call([$ctrl, 'cat'], $args);
		
	});

    // 实现隐式路由
    Route::any('/{class?}/{action?}/{args?}', function($class='Home', $action='__invoke', $args=[NULL]) {
        $class = ucfirst($class);
        $path = "\\App\\Http\\Controllers\\Web\\";
        $path .= $class . "Controller";
        
        $class_arr = explode("_",$class);
        if(sizeof($class_arr)>1 && $class_arr[0] == 'Activity'){
            $path = "\\App\\Http\\Controllers\\Web\\Activity\\";
            $path .= ucfirst(implode("_",array_splice($class_arr,1))) . "Controller";
        }
        if(is_string($args)){ $args = [$args]; }  
        $ctrl = App::make($path);
        return App::call([$ctrl, $action], $args);
    });
});
